function BannerCss(imgw,imgh){
    var ratio=imgh/imgw;
    var count=$(".banner ul li").length;
    var w=parseFloat($("body").css("width")),
        h=ratio*w;
    $(".banner").css({"width":w+"px","height":h+"px"});
    $(".banner ul").css({"width":count*w+"px","height":h+"px","left":-w+"px"});
    $(".banner ul li").css({"width":w+"px","height":h+"px"});
    $(".banner ul li img").css({"width":"auto","height":h+"px"});
    $(".banner ol li").length<6?$(".banner ol").css("left","46%"):null;
}
function Banner(){
    var w=parseFloat($("body").css("width")),
        ul=$(".banner ul");
    var timer=setInterval(function(){
        var active=$(".banner .active");
        LRSlide("left",ul,active,w);
    },2500);
    var container=document.getElementsByClassName("container")[0];
    var startX,startY,endX,endY,direction;
    EventUtil.addHandler(container,"touchstart",function(e){
        startX = e.touches[0].pageX;
        startY = e.touches[0].pageY;
    });
    EventUtil.addHandler(container,"touchmove",function(e){
        e.preventDefault();
        endX = e.changedTouches[0].pageX;
        endY = e.changedTouches[0].pageY;
        direction = GetSlideDirection(startX, startY, endX, endY);
    });
    EventUtil.addHandler(container,"touchend",function(){
        if(direction){
            var active=$(".banner .active");
            switch (direction){
                case 3:
                    LRSlide("left",ul,active,w);
                    break;
                case 4:
                    LRSlide("right",ul,active,w);
                    break;
                default:
            }
        }
    });
}
function LRSlide(turn,ul,active,w){
    var left=parseFloat(ul.css("left"));
    var index=$(".banner li").index($(".banner .active"));
    ul.addClass("t");
    switch (turn){
        case "left":
            var ele=active.next();
            var ele_ele=ele.next();
            var n=1;
            ul.css("left",-w*(index+1));
            break;
        case "right":
            var ele=active.prev();
            var ele_ele=ele.prev();
            var n=ul.children().length-2;
            ul.css("left",-w*(index-1));
            break;
    }
    ele.addClass("active")
        .siblings().removeClass("active");
    if(!ele_ele[0]){
        setTimeout(function(){
            ul.removeClass("t");
            ul.css("left",-n*w);
        },300);
        active.parent().children(":nth-child("+(n+1)+")").addClass("active")
            .siblings().removeClass("active");
    }
}
function GetSlideAngle(dx,dy) {
    return Math.atan2(dy,dx)*180/Math.PI;
}
function GetSlideDirection(startX,startY, endX, endY) {
    var dy = startY - endY;
    var dx = endX - startX;
    var result = 0;
    if (Math.abs(dx) < 2 && Math.abs(dy) < 2) {
        return;
    }
    var angle = GetSlideAngle(dx, dy);
    if (angle >= -45 && angle < 45) {
        result = 4;
    }else if (angle >= 45 && angle < 135) {
        result = 1;
    }else if (angle >= -135 && angle < -45) {
        result = 2;
    }else if ((angle >= 135 && angle <= 180) || (angle >= -180 && angle < -135)) {
        result = 3;
    }
    return result;
}